<?php

	include_once("Table.php");

    ob_start();
    include_once(INCLUDE_DIR. "/Category.php");
    ob_clean();

	class Product extends Table
	{
	    function Product($myMySQL, $table = "product")
	    {
	        $this->myMySQL = $myMySQL;
	        $this->table = DB_PRE.$table;
	    }


        function getIsOnline()
        {
            return array('Y' => '是', 'N' => '否');
        }


        function getData($row)
        {
            $isOnlineMap = $this->getIsOnline();

            $myCategory = new Category($this->myMySQL);

            $category_no = !empty($row['category_no']) ? $row['category_no'] : 0;

            $title = $myCategory->getValue('title', "no = ". $category_no);

            $dataArray = array();
            $dataArray['{no}']              = $row['no'];
            $dataArray['{category_no}']     = $row['category_no'];
            $dataArray['{category_title}']  = $title;
            $dataArray['{title}']           = $row['title'];
            $dataArray['{pc_pic}']          = $row['pc_pic'];
            $dataArray['{wap_pic}']         = $row['wap_pic'];
            $dataArray['{add_time}']        = $row['add_time'];
            $dataArray['{update_time}']     = $row['update_time'];
            $dataArray['{sort}']            = $row['sort'];
            $dataArray['{is_online}']       = $row['is_online'];
            $dataArray['{banner_pic}']      = $row['banner_pic'];
            $dataArray['{thumb_pic}']       = $row['thumb_pic'];
            $dataArray['{is_online_title}'] = $isOnlineMap[ $row['is_online'] ];
            $dataArray['{description}']     = $row['description'];

            return $dataArray;
        }

        function getDataClean($row)
        {
            $isOnlineMap = $this->getIsOnline();

            $myCategory = new Category($this->myMySQL);

            $category_no = !empty($row['category_no']) ? $row['category_no'] : 0;

            $title = $myCategory->getValue('title', "no = ". $category_no);

            $dataArray = array();
            $dataArray['no']               = $row['no'];
            $dataArray['category_no']      = $row['category_no'];
            $dataArray['category_title']   = $title;
            $dataArray['title']            = $row['title'];
            $dataArray['add_time']         = $row['add_time'];
            $dataArray['update_time']      = $row['update_time'];
            $dataArray['sort']             = $row['sort'];
            $dataArray['is_online']        = $row['is_online'];
            $dataArray['banner_pic']       = FILE_URL.$row['banner_pic'];
            $dataArray['thumb_pic']        = FILE_URL.$row['thumb_pic'];
            $dataArray['is_online_title']  = $isOnlineMap[ $row['is_online'] ];
            $dataArray['description']      = $row['description'];

            $pc_pic = json_decode($row['pc_pic'], true);
            $wap_pic = json_decode($row['wap_pic'], true);

            for($i = 0; isset($pc_pic[$i]); $i++)
            {
                $pc_pic[$i] = FILE_URL.$pc_pic[$i];
            }

            for($i = 0; isset($wap_pic[$i]); $i++)
            {
                $wap_pic[$i] = FILE_URL.$wap_pic[$i];
            }

            $dataArray['pc_pic']  = $pc_pic;
            $dataArray['wap_pic'] = $wap_pic;

            return $dataArray;
        }
	}

?>